#include "mybtnmaxtri.h"


static btnmaxtri_1(void)
{
    //创建按钮矩阵
    lv_obj_t* btnm = lv_btnmatrix_create(lv_scr_act());
    lv_obj_set_size(btnm, 600, 340);
    lv_obj_align(btnm, LV_ALIGN_CENTER, 0 , 0);

    //定义按钮数组，最后一个元素必须为空
    // static const char* map[] = {"btn1", "\n", "btn2", "btn3", ""};
    // static const char* map[] = 
    // {
    //     "1", "2", "3", "\n",
    //     "4", "5", "6", "\n",
    //     "7", "8", "9",     
    //  ""};
    lv_btnmatrix_set_btn_ctrl(btnm, 0, LV_BTNMATRIX_CTRL_RECOLOR);
    static const char* map[] = {"#ff0000 btn1#", "\n", "btn2", "btn3", ""};

    //设置按钮
    lv_btnmatrix_set_map(btnm, map);
}

lv_obj_t *label;
lv_obj_t *input;
lv_obj_t *input_label;
lv_obj_t *btnm;

static void event_cb(lv_event_t* e)
{
    uint8_t id;
    lv_obj_t* target = lv_event_get_target(e);
    id = lv_btnmatrix_get_selected_btn(target);
    lv_label_set_text(input_label, lv_btnmatrix_get_btn_text(target, id));
}

static void btnmaxtri_2(void)
{
    //1.创建USER标签
    label = lv_label_create(lv_scr_act());
    lv_label_set_text(label, "USER");
    lv_obj_set_style_text_font(label, &lv_font_montserrat_20, LV_PART_MAIN);
    lv_obj_align(label, LV_ALIGN_LEFT_MID,150,-100);

    //2.创建输入框
    input = lv_obj_create(lv_scr_act());
    lv_obj_set_size(input, 170,40);
    lv_obj_align_to(input, label, LV_ALIGN_OUT_BOTTOM_MID,0,20);
    //去除边框
    lv_obj_set_style_border_width(input, 0 ,0);
    //设置圆角
    lv_obj_set_style_radius(input, 20,0);
    //去除滚动条
    lv_obj_remove_style(input, NULL, LV_PART_SCROLLBAR);

    //3.创建输入框标签
    input_label = lv_label_create(input);
    lv_obj_align_to(input_label, input,LV_ALIGN_TOP_MID,0, -10);
    lv_obj_set_size(input_label, 40, 40);
    lv_obj_set_style_text_font(input_label, &lv_font_montserrat_20, LV_PART_MAIN);
    lv_label_set_text(input_label, "");

    //4.设置按钮矩阵
    btnm = lv_btnmatrix_create(lv_scr_act());
    //定义按钮数组，最后一个元素必须为空
    static const char* map[] = 
    {"1", "2","3","\n",
    "4", "5","6","\n",
    "7", "8","9","\n",
    "#", "0","%","",};

    //设置按钮
    lv_btnmatrix_set_map(btnm, map);
    lv_obj_align(btnm, LV_ALIGN_RIGHT_MID, -50, 0);
    lv_obj_set_size(btnm, 300, 300);
    lv_obj_set_style_text_font(btnm, &lv_font_montserrat_20, LV_PART_ITEMS);

    lv_btnmatrix_set_btn_ctrl_all(btnm, LV_BTNMATRIX_CTRL_CHECKABLE);
    lv_btnmatrix_set_one_checked(btnm, true);

    //5.按钮矩阵（优化界面）
    //去除边框
    lv_obj_set_style_border_width(btnm, 0,LV_PART_MAIN);
    //主体背景透明度
    lv_obj_set_style_bg_opa(btnm, 0, LV_PART_MAIN);
    //按钮背景透明度
    lv_obj_set_style_bg_opa(btnm, 0, LV_PART_ITEMS);
    //去除按钮阴影
    lv_obj_set_style_shadow_width(btnm, 0, LV_PART_ITEMS);
    lv_obj_add_event_cb(btnm, event_cb, LV_EVENT_PRESSED, NULL);
}


void mybtnmaxtri_example(void)
{
    btnmaxtri_2();
}